ajout svn:ignore.
[minwii.git] / WiiMouse IR G.PIE
1 Wiimote1.led1 = true
2 Wiimote2.led1 = true
3 Wiimote2.led4 = true
4 Wiimote3.led2 = true
5 Wiimote4.led2 = true
6 Wiimote4.led4 = true
7 Wiimote5.led3 = true
8 Wiimote6.led3 = true
9 Wiimote6.led4 = true
10 //Mouse Control Script using IR
11 //by vkapadia with much assistance from inio
12 //vkapadia@vkapadia.com
13 //
14 //Calibration:
15 //To calibrate, run this program and put the Wiimote on a flat surface face-up.
16 //Then read the values in the debug line (next to the run button).
17 //Change these values until the debug line reads approx. all zeros.
18 var.xtrim = -7
19 var.ytrim = -17
20 var.ztrim = -7
21 //
22 //Options:
23 var.deadzone = 5 //distance in pixels that you have to move the wiimote in
24 //order for it to register movement. Creates a "dead zone" around the pointer
25 //to make it easier to click. Higher = smoother but less accurate.
26 //fake cursor init
27 cursor2.visible = true
28 //more options to be added later
29
30 //Controls:
31 //Point Wiimote = Move Mouse
32 //D-Pad = Arrow Keys
33 //B-Button = Left Click
34 //Home = Middle Click
35 //A-Button = Right Click
36 //Plus and Minus = Control Volume
37 //One = Unmapped
38 //Two = Unmapped
39 //
40 //If the pointer hits the edge of the screen, the Wiimote will rumble a bit.
41 //
42 //The LEDs attempt to emulate KITT's grill from Knight Rider
43
44 //***Do not edit anything below this line unless you know what you are doing.***
45 var.accx = wiimote.RawForceX + var.xtrim
46 var.accy = wiimote.RawForceY + var.ytrim
47 var.accz = wiimote.RawForceZ + var.ztrim
48
49 if wiimote.dot1vis and wiimote.dot2vis then
50
51 if var.accy > -7 then
52 var.orientation = 0
53 elseif var.accy > -45 then
54 if var.accx < 0 then
55 var.orientation = 3
56 else
57 var.orientation = 1
58 endif
59 else
60 var.orientation = 2
61 endif
62
63 if var.leftpoint = 0 then
64 if var.orientation = 0 then
65 if wiimote.dot1x < wiimote.dot2x then
66 var.leftpoint = 1
67 else
68 var.leftpoint = 2
69 endif
70 endif
71 if var.orientation = 1 then
72 if wiimote.dot1y > wiimote.dot2y then
73 var.leftpoint = 1
74 else
75 var.leftpoint = 2
76 endif
77 endif
78 if var.orientation = 2 then
79 if wiimote.dot1x > wiimote.dot2x then
80 var.leftpoint = 1
81 else
82 var.leftpoint = 2
83 endif
84 endif
85 if var.orientation = 3 then
86 if wiimote.dot1y < wiimote.dot2y then
87 var.leftpoint = 1
88 else
89 var.leftpoint = 2
90 endif
91 endif
92 endif
93
94 if var.leftpoint = 1 then
95 var.fix1x = wiimote.dot1x
96 var.fix1y = wiimote.dot1y
97 var.fix2x = wiimote.dot2x
98 var.fix2y = wiimote.dot2y
99 else
100 var.fix1x = wiimote.dot2x
101 var.fix1y = wiimote.dot2y
102 var.fix2x = wiimote.dot1x
103 var.fix2y = wiimote.dot1y
104 endif
105
106 var.dx = var.fix2x - var.fix1x
107 var.dy = var.fix2y - var.fix1y
108 var.cx = (var.fix1x+var.fix2x)/1024.0 - 1
109 var.cy = (var.fix1y+var.fix2y)/1024.0 - .75
110
111 var.d = sqrt(var.dx*var.dx+var.dy*var.dy)
112
113 var.dx = var.dx / var.d
114 var.dy = var.dy / var.d
115
116 var.ox = -var.dy*var.cy-var.dx*var.cx;
117 var.oy = -var.dx*var.cy+var.dy*var.cx;
118
119 var.ax = (var.ox * screen.desktopwidth) + (screen.desktopwidth / 2)
120 var.ay = (-var.oy * screen.desktopwidth) + (screen.desktopheight / 2)
121
122 var.dx = var.ax - cursor2.posx
123 var.dy = var.ay - cursor2.posy
124
125 var.d = sqrt((var.dx*var.dx)+(var.dy*var.dy))
126
127 var.a = 180 / (200 + var.d * var.d * var.d * .001)
128
129 if var.d <= var.deadzone then var.a = 1
130
131 //debug = var.d + " " + var.a
132
133 var.finalx = cursor2.posx * var.a + var.ax * (1 - var.a)
134 var.finaly = cursor2.posy * var.a + var.ay * (1 - var.a)
135
136
137 cursor2.posx = smooth(var.finalx,3,5)
138 cursor2.posy = smooth(var.finaly,3,5)
139
140 else
141
142 var.leftpoint = 0
143
144 endif
145
146 var.xpos = var.finalx
147 var.ypos = var.finaly
148 ppjoy1.analog0 = ensuremaprange(var.xpos,0,screen.desktopwidth,-1,1)
149 ppjoy1.analog1 = ensuremaprange(var.ypos,0,screen.desktopheight,-1,1)
150
151 if wiimote1.B == true
152 ppjoy1.digital0 = true
153 else
154 ppjoy1.digital0 = false
155 endif
156
157 debug = var.xpos+ " " + var.ypos